<template>
  <div class="ele-body">
    <!-- 搜索表单 -->

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="ranchId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          v-model:selection="selection"
          :scroll="{ x: 'max-content' }"
        >

          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a @click="openPolygonListDialog(record)">多边形围栏</a>
              </a-space>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>

    <!-- 编辑弹窗 -->
    <VehicleManagerGeofenceRanchManagerFencelist v-if="showPolygonList" v-model:listVisible="showPolygonList" :data="current" @done="reload" />
  </div>
</template>

<script>
import { RanchApi } from '@/api/property/RanchApi';
import VehicleManagerGeofenceRanchManagerFencelist from './ranchfence/ranchfence-fencelist.vue'
export default {
  name: 'VehicleManagerGeofenceRanchManager',
  components: {
    VehicleManagerGeofenceRanchManagerFencelist
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '名字',
          dataIndex: 'ranchName'
        },
        {
          title: '简称',
          dataIndex: 'shortRanchName'
        },
        {
          title: '地址',
          dataIndex: 'address',
        },
        {
          title: '创办时间',
          dataIndex: 'establishTime'
        },
        {
          title: '操作',
          key: 'action',
          width: 280,
          align: 'center'
        }
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showPolygonList: false,
    };
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2022/03/04 00:27
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2022/03/04 00:27
     */
    reset() {
      this.where = {};
      this.reload();
    },

    /**
     * 打开新增或编辑弹窗
     *
     * @author cancan
     * @date 2023/10/14 09:52
     */
    openPolygonListDialog(row) {
      this.current = row;
      this.showPolygonList = true;
    },

    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return RanchApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    }
  }
};
</script>
